#INCLUDE "PROTHEUS.CH"
#INCLUDE "APWEBEX.CH"

User Function fswpva03
local 		cHtml	:= ""
local		NX 		:= 0
local		cErro	:= ""
local		NY 		:= 0
Private 	oObj 	:= Nil

WEB EXTENDED INIT cHtml

If !Empty(HttpSession->aUser) .and. !Empty(HttpSession->aComan)
	Return cHtml := ExecInPage("fswpvh03")
ElseIf !Empty(HttpSession->aUser) .and. Empty(HttpSession->aComan)
	If Empty(HTTPPOST->cComanda)
		Return cHtml := RedirPage("u_fswpva02.apw")
	Else
		oObj := WSFSWWSS01():New()
		oObj:CNMCOMANDA := HTTPPOST->cComanda
		If oObj:GETCOMANDA()
			HttpSession->aComan := {HTTPPOST->cComanda}
			HttpSession->aLista := {}
			conout("Usuario : "+HttpSession->aUser[2]+" Carrega Comanda : "+HTTPPOST->cComanda)
			FOR NX:=1 TO Len(oObj:OWSGETCOMANDARESULT:OWSCOMANDAVIEW)
				AADD(HttpSession->aLista,{oObj:OWSGETCOMANDARESULT:OWSCOMANDAVIEW[NX]:NZ2_QUANT,;
											  oObj:OWSGETCOMANDARESULT:OWSCOMANDAVIEW[NX]:CZ2_PRODUTO,;
											  oObj:OWSGETCOMANDARESULT:OWSCOMANDAVIEW[NX]:NZ2_VLUNIT,;
											  oObj:OWSGETCOMANDARESULT:OWSCOMANDAVIEW[NX]:CZ2_ITEM,;
											  1})
				conout(str(oObj:OWSGETCOMANDARESULT:OWSCOMANDAVIEW[NX]:NZ2_QUANT,3)+" | "+oObj:OWSGETCOMANDARESULT:OWSCOMANDAVIEW[NX]:CZ2_PRODUTO+" | "+str(oObj:OWSGETCOMANDARESULT:OWSCOMANDAVIEW[NX]:NZ2_VLUNIT,3)+" | "+oObj:OWSGETCOMANDARESULT:OWSCOMANDAVIEW[NX]:CZ2_ITEM+" | 1")
			NEXT NX

			aSort(HttpSession->aLista,,,{|x,y| x[4] < y[4]})
			
			cHtml := "OK"
		Else	
			cHtml := GetWSCerror(3)
		EndIf
	EndIf
Else
	Return cHtml := RedirPage("u_fswpva01.apw")
EndIf

WEB EXTENDED END
Return cHtml